<?php
/**
 * Created by PhpStorm.
 * User: zhang
 * Date: 2018/4/17
 * Time: 12:39
 */
namespace app\common\model;

use think\Controller;

class Base extends Controller{
    public $check;
    public $mysql;
    public $jwt;

    function __construct(){
        error_reporting(E_ERROR | E_WARNING | E_PARSE);//规避一般错误
        /*if(!$this->isMD5Verify()){
            echo echoJson(0, "数据验证失败!");
        }*/

        header("Access-Control-Allow-Origin: http://a.com"); // 允许a.com发起的跨域请求
//如果需要设置允许所有域名发起的跨域请求，可以使用通配符 *
        header("Access-Control-Allow-Origin: *"); // 允许任意域名发起的跨域请求
        header('Access-Control-Allow-Headers: X-Requested-With,X_Requested_With');
        
        $this->check = new Check();
        $this->mysql = new Mysql();
        $this->jwt = new Jwt_base();

        $token = $_SERVER["HTTP_X_TOKEN"];


/*        if(empty($token)){
            echoJson(0, "token无效,请登录使用");
        }else if($token !== "none")
            $this->jwt->decode($token);*/
    }

    function token($uid,$username){
        return $this->jwt->encode($uid,$username);
    }

    function isMD5Verify($isVerify = true) {
        if ($isVerify && isset($_REQUEST) && count($_REQUEST) > 0) {
            $jammer = "ZZKDN232BAGINE32ID00000021";
            $parameters = array();
            foreach ($_REQUEST as $key => $value) {
                if ($key != "secretkey") {
                    $parameters[] = strtoupper($key . $value);
                }
            }
            sort($parameters);
            $original = implode("", $parameters);
            $Md5 = md5($original . $jammer);
            if (isset($_REQUEST['secretkey']) && $_REQUEST['secretkey'] == $Md5) {
                return true;
            } else {
                return false;
            }
        } else {
            return true;
        }
    }

    /*
        function isNull($tel, $passd) {
            if (empty($tel)) {
                echo echoJson(0, "电话号为空或不合法!");
                return false;
            }
            if (empty($passd)) {
                echo echoJson(0, "密码为空或不合法!!");
                return false;
            }
            return true;
        }
    */
    
}